package com.lcm.oj.lanqiao.year2021.moni.demo;

import java.util.HashSet;

/**
 * @author Coder-lcm
 * @date 2021/4/17
 */
public class QuanPaiLie2 {
    static int[] a = {1,1,1,2,2,2,3,3,3};
    static int n = 9, ans = 0;
    static HashSet<String> set = new HashSet<>();

    static void swap(int i, int j) {
        int t = a[i];
        a[i] = a[j];
        a[j] = t;
    }

    static void dfs(int m) {
        if(m >= n) {
            ans++;
            String s = "";
            for (int i = 0; i < n; i++) {
                s += a[i];
                System.out.print(a[i] +" ");
            }
            System.out.println();
            set.add(s);
            return;
        }
        for (int i = m; i < n; i++) {
            swap(i, m);
            dfs(m+1);
            swap(i, m);
        }
    }

    public static void main(String[] args) {
        dfs(0);
        System.out.println(ans);
        System.out.println(set.size());
    }
}
